{% extends 'base.html' %}

{% load staticfiles %}

{% block title %}课程机构{% endblock %}

{% block crumbs%}
<!--crumbs start-->
<section>
    <div class="wp">
        <ul  class="crumbs">
            <li><a href="{% url 'index' %}">首页</a>></li>
            <li>课程机构</li>
        </ul>
    </div>
</section>
{% endblock %}

{% block body %}
<section>
<div class="wp butler_list_box list">
	<div class='left'>
{#根据类别、城市筛选机构#}
		<div class="listoptions">
			<ul>
				<li>
					<h2>机构类别</h2>
					<div class="cont">
                        <a href="?city={{ city_id }}"><span class="{% ifequal category '' %}active2{% endifequal %}">全部</span></a>

                            <a href="?ct=pxjg&city={{ city_id }}{% if keywords %}&keywords={{ keywords }}{% endif %}"><span class="{% ifequal category 'pxjg' %}active2{% endifequal %}">培训机构</span></a>

                            <a href="?ct=gx&city={{ city_id }}{% if keywords %}&keywords={{ keywords }}{% endif %}"><span class="{% ifequal category 'gx' %}active2{% endifequal %}">高校</span></a>

                            <a href="?ct=gr&city={{ city_id }}{% if keywords %}&keywords={{ keywords }}{% endif %}"><span class="{% ifequal category 'gr' %}active2{% endifequal %}">个人</span></a>

					</div>
				</li>
				<li>
					<h2>所在地区</h2>
					<div class="more">更多</div>
					<div class="cont">
                        <a href="?ct={{ category }}"><span class="{% if not city_id %}active2{% endif %}">全部</span></a>
                        {% for city in all_citys %}
                            <a href="?city={{ city.id }}&ct={{ category }}{% if keywords %}&keywords={{ keywords }}{% endif %}"><span class="{% ifequal city_id city.id %}active2{% endifequal %}">{{ city.name }}</span></a>

                        {% endfor %}

					</div>
				</li>
			</ul>
		</div>
        <div class="all">共<span class="key">{{ org_nums }}</span>家</div>
    <div class="butler_list company list">
		<div class="layout">
{#排序功能#}
			<div class="head">
				<ul class="tab_header">
					<li class="{% ifequal sort '' %}active{% endifequal %}"><a href="?ct={{ category }}&city={{ city_id }}">全部</a> </li>
					<li class="{% ifequal sort 'students' %}active{% endifequal %}"><a href="?sort=students&ct={{ category }}&city={{ city_id }}">学习人数 &#8595;</a></li>
					<li class="{% ifequal sort 'courses' %}active{% endifequal %}"><a href="?sort=courses&ct={{ category }}&city={{ city_id }}">课程数 &#8595;</a></li>
				</ul>
			</div>
{#机构列表，使用分页后的对象object_list方法#}
            {% for org in all_orgs.object_list %}
                <dl class="des difdes">
                    <dt>
                        <a href="{% url 'org:org_home' org.id %}">
                            <img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ org.image }}"/>
                        </a>
                    </dt>
                    <dd>
                        <div class="clearfix">
                             <a href="{% url 'org:org_home' org.id %}">
                                 <h1>{{ org.name }}</h1>
                                 <div class="pic fl">
                                     {% if org.is_authentication %}
                                          <img src="{% static 'images/authentication.png' %}"/>
                                     {% endif %}
                                     {% if org.is_gold %}
                                         <img src="{% static 'images/gold.png' %}"/>
                                     {% endif %}
                                 </div>
                             </a>
                        </div>
                        <ul class="cont">
                            <li class="first">
                                <p class="pic9">课程数：<span>{{ org.course_nums }}</span></p>
                                <p class="c7">学习人数：<span>{{ org.students }}</span></p></li>
                            <li class="c8" style="padding-left:18px;">{{ org.address }}</li>
                            <li class="pic10" style="padding-left:18px;">经典课程：

                                    <a href="/diary/19/">c语言基础入门</a>

                                    <a href="/diary/16/">数据库基础</a>

                            </li>
                        </ul>
                    </dd>
                    <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
                </dl>
                {% endfor %}
		</div>
{#分页功能#}
		 <div class="pageturn">
             <ul class="pagelist">
                <li class="long">
                    {% if all_orgs.has_previous %}
                    <a href="?{{ all_orgs.previous_page_number.querystring }}" class="prev">上一页</a>
                    {% endif %}
                </li>

                {% for page in all_orgs.pages %}
                 {% if page %}

                    {% ifequal page all_orgs.number %}
                        <li class="active"><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
                    {% else %}
                        <li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
                    {% endifequal %}

                 {% else %}
                        <li class="none"><a href="">...</a></li>
                 {% endif %}

                {% endfor %}

                {% if all_orgs.has_next %}
                <li class="long"><a href="?{{ all_orgs.next_page_number.querystring }}">下一页</a></li>
                {% endif %}
             </ul>
        </div>
    </div>
	</div>
{#用户咨询窗口#}
	<div class="right companyright">
        <div class="head">我要学习</div>
        <form class="rightform" id="jsStayForm">
            <div>
                <img src="{% static 'images/rightform1.png' %}"/>
                <input type="text" name="name" id="companyName" placeholder="名字" maxlength="25" />
            </div>
            <div>
                <img src="{% static 'images/rightform2.png' %}"/>
                <input type="text" name="mobile" id="companyMobile" placeholder="联系电话"/>
            </div>
            <div>
                <img src="{% static 'images/rightform3.png' %}"/>
                <input type="text" name="course_name" id="companyAddress" placeholder="课程名" maxlength="50" />
            </div>
            <p class="error company-tips" id="jsCompanyTips"></p>
            <input class="btn" type="text" id="jsStayBtn" value="立即咨询 >" />

        {% csrf_token %}
        </form>
    </div>
{#右侧机构排名#}

		<div class="right companyrank layout">
			<div class="head">授课机构排名</div>
            {% for hot_org in hot_orgs %}
                <dl class="des">
{#                    计数器#}
                    <dt class="num fl">{{ forloop.counter }}</dt>
                    <dd>
                        <a href="{% url 'org:org_home' hot_org.id %}"><img width="100" height="30" src="{{ MEDIA_URL }}{{ hot_org.image }}"></a>
                        <a href="{% url 'org:org_home' hot_org.id %}"><h1>{{ hot_org.name }}</h1></a>
                        <p>{{ hot_org.city }}</p>
                    </dd>
                </dl>
              {% endfor %}
		</div>
</div>
</section>
{% endblock %}


{% block custom_js %}

{#用户咨询数据处理#}
{#参考jQuery手册#}
{#ajax，通过 HTTP 请求加载远程数据，.ajax()函数依赖服务器提供的信息来处理返回的数据。#}
<script>
    $(function(){
        {#绑定click事件#}
        $('#jsStayBtn').on('click', function(){
            $.ajax({
                {#是否缓存此页面#}
                cache: false,
                {#发送给后端的方式#}
                type: "POST",
                {#dataType:"json",#}
                {#发送给端的路由#}
                url:"{% url 'org:user_ask' %}",
                {# 设置发送给服务器的数据，serialize()方法将结果转换为字符串,同时将 csrf token 一块序列化过来 #}
                data:$('#jsStayForm').serialize(),
                {#(默认: true) 默认设置下，所有请求均为异步请求。如果需要发送同步请求，
                请将此选项设置为 false。注意，同步请求将锁住浏览器，用户其它操作必须等待请求完成才可以执行#}
                async: true,
                {#success：请求成功后的回调函数#}
                success: function(data) {
                    if(data.status == 'success'){
                        $('#jsStayForm')[0].reset();
                        alert("提交成功")
                    }else if(data.status == 'fail'){
                        $('#jsCompanyTips').html(data.msg)
                    }
                },
            });
        });
    })

</script>
{% endblock %}
